package d0319;

public class Eaggtest {
    volatile boolean hasEaggs = false;
    Thread human = new Thread(() -> {
        while (true) {
            if (!hasEaggs) {
                System.out.println("等待");
            } else {
                System.out.println("收取");
                hasEaggs = false;
            }
        }
    });


    Thread hen = new Thread(() -> {
        while (true) {
            try {
                Thread.sleep(3000
                );
            } catch (InterruptedException e) {
                e.printStackTrace();

                hasEaggs = true;
            }
        }
    });


    public static void main(String[] args) {
        Eaggtest eaggtest = new Eaggtest();
        eaggtest.hen.start();
        eaggtest.human.start();
    }
}